// 主界面
;define(function(require, exports, module) {
    'use strict';
    var util = require("util");
    var base = require(CONFIG.BasePath + "js/enterprise/base");
    var router = require("../hash/pageRouter");
    var constant = require("constant");
    var css_detail = require("./clientInfo.css");
    var databind = require("databind");
    var pageIndex = 1,
		pageSize = 10,
		totalPageCount = 1,
		totalRecordCount = 0; //分页初始化
    
    var init = function(){
    	router.init();
    	inquireOwnEnterprisePageList();
		initEvent();
    };
    
	var initEvent = function(){
		if(base.getData("sid")==null){
			location.href="../login/login.html";
		}
		
		$("#clientInfo .searchBtn").unbind("click").click(function(){
			pageIndex = 1;
			pageSize = 10;
			totalPageCount = 1;
			totalRecordCount = 0; //分页初始化				
			inquireOwnEnterprisePageList();
		});
    };
    
	//获取企业用户列表
	var inquireOwnEnterprisePageList = function(){
		var body = base.parseForm($("#clientInfo .searchBox"));
		body.createDateTimeBegin = body.createDateTimeBegin.split("-").join("");
		body.createDateTimeEnd = body.createDateTimeEnd.split("-").join("");
        base.fnAjax({
            action: "inquireOwnEnterprisePageList.json",
            oData: {
            	enterpriseType: 0,
            	pageIndex: pageIndex,
                pageSize: pageSize,
                mobile:body.mobile,
                enterpriseName:body.enterpriseName,
                legalPerson:body.legalPerson,
                state:body.state,
                auditState:body.auditState,
                createDateTimeBegin:body.createDateTimeBegin,
                createDateTimeEnd:body.createDateTimeEnd,
                tradeType: body.tradeType
            }, //传递参数
            fnSuccess: function(data) {
                if (data.status == 200) {
                	juicer.register("getValueByKey", constant.getValueByKey);
                	var tpl = $("#clientInfo script").html();
                    var html = juicer(tpl, data);
                    $("#clientInfo table").html(html);
                    totalPageCount = data.totalPageCount;
                    totalRecordCount = data.totalRecordCount;
                    base.pageControl(
                    	$("#clientInfo .pagerCon"),
                        totalRecordCount,
                        data.pageIndex,
                        data.pageSize,
                        function(p) {
                            pageIndex = p;
                            inquireOwnEnterprisePageList();
                    });
                    
//                   //点击详情
//			        $("#clientInfo").on("click",".table_details_link",function(){
//			            var enterpriseIds = [];
//			            var $this = $(this).parents("tr.tr_style");
//						enterpriseIds.push($this.attr("enterpriseId"));
//						router.route("client/clientManage_details.html?enterpriseId="+enterpriseIds,true);
//			        });
                } else {
                    base.alert(2,"信息获取失败");
                }
            }
		});
	};
	
    return {
        init:init
    };
});